package com.android.accessibility.view;

import android.content.Context;
import android.graphics.ColorFilter;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.RadioButton;

public class CustomRadio extends RadioButton {

    private static final ColorFilter sGridColorFilter;
    static {
        ColorMatrix colorMatrix = new ColorMatrix();
        colorMatrix.setSaturation(0);
        sGridColorFilter= new ColorMatrixColorFilter(colorMatrix); 
    }
    public CustomRadio(Context context) {
        super(context);
    }

    public CustomRadio(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomRadio(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public void setChecked(boolean checked) {
        super.setChecked(checked);
        Drawable[] drawables = getCompoundDrawables();
        Drawable drawableTop = null;
        if (drawables != null && drawables.length >= 4) {
            drawableTop = drawables[1];
        }
        if (drawableTop != null) {
            if (checked) {
                drawableTop.clearColorFilter();
            } else {
                drawableTop.setColorFilter(sGridColorFilter);
            }
        }
    }
}
